﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Medianamik.Core.Sugar;
using NUnit.Framework;

namespace Medianamik.Tests.Unit.Medianamik.Core.Sugar
{
    [TestFixture ]
    public class DataUtilTest
    {
        public List<Guid> Guids
        {
            get;
            set;
        }

        public string Path
        {
            get;
            set;
        }

        [SetUp]
        public void Init()
        {
            //Generate a few Guid
            Guids = 6.Times(() => Guid.NewGuid()).ToList();
            //Generate the path string
            Path = Guids.Aggregate(new StringBuilder('.'), (sb, id) => sb.Append(id).Append('.'), (sb) => sb.ToString());
        }

        [Test]
        public void GetBottomToTopNodeIds_should_return_first_nodeId_last()
        {
            var list = DataUtil.GetBottomToTopNodeIds(Path, true, 0);
            Assert.AreEqual(Guids.First(), list.Last());
        }

        [Test]
        public void GetBottomToTopNodeIds_with_inclusive_should_return_last_nodeId_first()
        {
            var list = DataUtil.GetBottomToTopNodeIds(Path, true, 0);
            Assert.AreEqual(Guids.Last(), list.First());
        }

        [Test]
        public void GetBottomToTopNodeIds_with_noninclusive_should_return_penultimate_nodeId_first()
        {
            var list = DataUtil.GetBottomToTopNodeIds(Path, false, 0);
            Assert.AreEqual(Guids.Except(new Guid[]{Guids.Last()}).Last() , list.First());
        }

    }
}